using LocalOverride.Fiddler.Store;
using NUnit.Framework;

namespace LocalOverride.Tests.UrlMapping
{
    [TestFixture]
    public class MappingEntryUndoTests
    {
        [Test]
        public void CanRestoreUrlState()
        {
            const string initialValue = "http://test.com";
            const string changeValue = "http://blah.com";

            var mapping = new MappingEntry { Url = initialValue };

            Assert.AreEqual(initialValue, mapping.Url);

            mapping.BeginChange();

            mapping.Url = changeValue;

            Assert.AreEqual(changeValue, mapping.Url);

            mapping.CancelChange();

            Assert.AreEqual(initialValue, mapping.Url);
        }

        [Test]
        public void CanRestoreLocalPathState()
        {
            const string initialValue = "c:\temp";
            const string changeValue = "c:\blah";

            var mapping = new MappingEntry { LocalPath = initialValue };

            Assert.AreEqual(initialValue, mapping.LocalPath);

            mapping.BeginChange();

            mapping.LocalPath = changeValue;

            Assert.AreEqual(changeValue, mapping.LocalPath);

            mapping.CancelChange();

            Assert.AreEqual(initialValue, mapping.LocalPath);
        }

        [Test]
        public void CanRestoreIsDirectoryState()
        {
            const bool initialValue = true;
            const bool changeValue = false;

            var mapping = new MappingEntry { IsDirectory = initialValue };

            Assert.AreEqual(initialValue, mapping.IsDirectory);

            mapping.BeginChange();

            mapping.IsDirectory = changeValue;

            Assert.AreEqual(changeValue, mapping.IsDirectory);

            mapping.CancelChange();

            Assert.AreEqual(initialValue, mapping.IsDirectory);
        }

        [Test]
        public void CanRestoreDownloadLocalCopyState()
        {
            const bool initialValue = true;
            const bool changeValue = false;

            var mapping = new MappingEntry { DownloadLocalCopy = initialValue };

            Assert.AreEqual(initialValue, mapping.DownloadLocalCopy);

            mapping.BeginChange();

            mapping.DownloadLocalCopy = changeValue;

            Assert.AreEqual(changeValue, mapping.DownloadLocalCopy);

            mapping.CancelChange();

            Assert.AreEqual(initialValue, mapping.DownloadLocalCopy);
        }

        [Test]
        public void CanRestoreFileExtensionsState()
        {
            var initialValue = new FileExtensionList{"css", "js"};
            var changeValue = new FileExtensionList { "css", "aspx" };

            var mapping = new MappingEntry { FileExtensions = initialValue };

            Assert.AreEqual(initialValue, mapping.FileExtensions);

            mapping.BeginChange();

            mapping.FileExtensions = changeValue;

            Assert.AreEqual(changeValue, mapping.FileExtensions);

            mapping.CancelChange();

            Assert.AreEqual(initialValue, mapping.FileExtensions);
        }

        [Test]
        public void CanRestoreDefaultFileNameState()
        {
            const string initialValue = "default.html";
            const string changeValue = "index.txt";

            var mapping = new MappingEntry { DefaultFileName = initialValue };

            Assert.AreEqual(initialValue, mapping.DefaultFileName);

            mapping.BeginChange();

            mapping.DefaultFileName = changeValue;

            Assert.AreEqual(changeValue, mapping.DefaultFileName);

            mapping.CancelChange();

            Assert.AreEqual(initialValue, mapping.DefaultFileName);
        }
    }
}